/*
 * CS_REQ_EVENT_DUNGEON_INFO.cpp
 *
 *  Created on: 2013. 8. 28.
 *      Author: mega@gamevil.com
 */


#include "../../User.h"
#include "../../NResource/Static.h"
#include "../../NLogic/Stamina.h"
#include "dungeon.h"

namespace ProjectZ { namespace NCommand { namespace NDungeon {

void CS_REQ_EVENT_DUNGEON_INFO::OnExecute(User * pUser, ::Network::Packet * pPacket)
{
	PREPARE_PACKET;

	NLogic::Stamina * pStamina = pUser->GetStamina();
	if (NULL == pStamina)
	{
		DEBUGLOG("%s : pStamina is NULL!!!", __FUNCTION__);
		SendPacket(pUser, ACK_UNKNOWN_ERROR, 0);
		return;
	}

	pStamina->InitializeEventDungeonKey();

	if (false == NResource::Static::InstancePtr()->GetEventTime()->IsOpenEventDungeon(pUser))
	{
		SendPacket(pUser, ACK_NOT_EVENT_DUNGEON, 0);
		return;
	}

	// 이벤트 던전 남은 시간
	int remainMin = NResource::Static::InstancePtr()->GetEventTime()->EventDungeonRemainMinute(pUser);
	SendPacket(pUser, ACK_OK, remainMin);






/*	// 이벤트 던전 오픈 기간이 아닌 경우 유저의 스태미너 초기화
	if (false == NResource::Static::InstancePtr()->GetEventTime()->IsOpenEventDungeon(pUser)
		&& false == NResource::Static::InstancePtr()->GetEventTime()->IsWorldBossEvent(pUser))
	{
		pUser->GetCharacterInfo().event_stamina = -1;
	}

	if (false == NResource::Static::InstancePtr()->GetEventTime()->IsOpenEventDungeon(pUser))
	{
		SendPacket(pUser, ACK_NOT_EVENT_DUNGEON, 0);
		return;
	}

	// 유저의 스태미너 회복 시간이 현재 이벤트 던전의 시작 시간 보다 작은 경우 유저의 스태미너 초기화
	NResource::EventTimeData::Key clsKey(NResource::EventTimeResource::EventType::EM_EVENT_TYPE_EVENT_DUNGEON_OPEN, 0);
	NResource::EventTimeData::Flyweight * pFly = NResource::Static::InstancePtr()->GetEventTime()->GetFly(pUser, clsKey);
	if (NULL == pFly)
		return;

	if (pFly->_START_SEC > static_cast<time_t>(pUser->GetCharacterInfo().recover_stamina_sec))
	{
		if (false == NResource::Static::InstancePtr()->GetEventTime()->IsWorldBossEvent(pUser))
			pUser->GetCharacterInfo().event_stamina = -1;
	}

	// 이벤트 던전 남은 시간
	int remainMin = NResource::Static::InstancePtr()->GetEventTime()->EventDungeonRemainMinute(pUser);

	SendPacket(pUser, ACK_OK, remainMin);*/
}

void CS_REQ_EVENT_DUNGEON_INFO::SendPacket(User * pUser, int16_t res, int remainMinute)
{
	::Network::Packet * pAck = ::Network::GETPACKETPOOL()->SEND_NEW();

	*pAck << res;
	*pAck << remainMinute;

	pAck->MakePacket(CMD_SC_REQ_EVENT_DUNGEON_INFO);
	pUser->Send(pAck);
}

} /*NDungeon*/ } /*NCommand*/ } /*ProjectZ*/
